//
//  ViewController.m
//  FliqFlicks
//
//  Created by EJ Lacap on 1/11/15.
//  Copyright (c) 2015 Lexnus. All rights reserved.
//

#import "ViewController.h"
#import "FlickManager.h"

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UILabel *lblWelcome;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    [self.lblWelcome setText:NSLocalizedString(@"Hello", @"Hello - Welcome Message")];
    
    NSLog(@"BaseURL :%@", [self readValueFromConfigurationFile]);
    
    [[FlickManager sharedManager] getSuggestedFlicksWithParams:@{@"api_key":@"e1024aa7aae73b32cebdc5a4b0922e91",@"sort_by":@"popularity.desc"} success:^(NSMutableArray *flicks) {
        
        NSManagedObjectContext* context = [RKManagedObjectStore defaultStore].mainQueueManagedObjectContext;
        //  NSManagedObjectContext* context =  [[[RKObjectManager sharedManager] managedObjectStore] mainQueueManagedObjectContext];
        NSError *error = nil;
        NSEntityDescription *entityDescription = [NSEntityDescription
                                                  entityForName:@"Flick" inManagedObjectContext: context];
        NSFetchRequest *request = [[NSFetchRequest alloc] init];
        [request setEntity:entityDescription];
        NSArray *dtContents = [context executeFetchRequest:request error:&error];
        NSLog(@"Content :%@", dtContents);
        
    } failure:^(RKObjectRequestOperation *operation, NSError *error) {
        
    }];
    
    
}

- (NSString *) readValueFromConfigurationFile {
    NSBundle *bundle = [NSBundle mainBundle];
    NSString *path = [bundle pathForResource:@"Configuration" ofType:@"plist"];
    NSDictionary *config = [NSDictionary dictionaryWithContentsOfFile:path];
    return config[@"BaseURL"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
